package phapp.service.qfd.impl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;
import javacommon.base.*;
import phapp.model.custom.Custom;
import phapp.model.custom.CustomFavorite;
import phapp.model.data.Qfdtext;
import phapp.model.luckstar.Stardeal;
import phapp.model.luckstar.Staruse;
import phapp.model.qfd.*;
import phapp.model.system.Version;
import phapp.dao.qfd.*;
import phapp.service.common.QfdException;
import phapp.service.custom.*;
import phapp.service.luckstar.*;
import phapp.service.qfd.impl.*;
import phapp.service.qfd.*;
import phapp.service.system.*;

/**
 * Title: t_custqfd_data 业务处理层 Description: spring事务实现层,调用Dao层取数据 Copyright:
 * Copyright (c) 2012-10 Company:
 * 
 * @author you name
 * @version 1.0
 */

@Component("custqfdManager")
@Transactional
public class CustqfdManagerImpl extends BaseManager<Custqfd, java.lang.Integer>
   implements CustqfdManager
{
   //添加灯油之后延长的天数
   public static final int LIGHT_OIL_TIME = 3;
   //添加灯油所消耗的幸运星
   public static final int LIGHT_OIL_STAR = 3;
   //放灯过滤状态
   public static final int LIGHT_FILTER_STATUS = 9;

   /** 定义Dao */
   private CustqfdDao custqfdDao;
   private CustomManager customManager;
   private StaruseManager staruseManager;
   private StardealManager stardealManager;
   private KeywordManager keywordManager;

   /** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性 */
   public void setCustqfdDao(CustqfdDao dao)
   {
      this.custqfdDao = dao;
   }

   /** 获取Dao */
   public EntityDao getEntityDao()
   {
      return this.custqfdDao;
   }

   public void setCustomManager(CustomManager customManager)
   {
      this.customManager = customManager;
   }
   
   public void setStaruseManager(StaruseManager staruseManager)
   {
      this.staruseManager = staruseManager;
   }

   public void setStardealManager(StardealManager stardealManager)
   {
      this.stardealManager = stardealManager;
   }

   public void setKeywordManager(KeywordManager keywordManager)
   {
      this.keywordManager = keywordManager;
   }

   /**
    * <p>
    * 分页查询Custqfd<br>
    * 
    * @param PageRequest
    *           pr
    * @return Page
    * @author
    */
   @Transactional(readOnly = true)
   public Page findByPageRequest(PageRequest pr)
   {
      return custqfdDao.findByPageRequest(pr);
   }

   /**
    * <p>
    * 批量删除 Custqfd<br>
    * 
    * @param Custqfd
    *           u
    * @return Boolean
    * @author
    */
   @Transactional(readOnly = true)
   public Boolean removeByIdArry(Custqfd u)
   {
      Boolean result = false;
      int i = -1, size = u.getIdList().size();
      i = custqfdDao.removeByIdArry(u);
      if (i == size)
      {
         result = true;
      }
      else
      {
         throw new RuntimeException();
      }
      return result;
   }

   public Map customBuyLight(JSONObject jsonData)
   {
      int nStatus = 0;
      Integer ReceiverID;
      Custqfd custqfdData = null;
      Custom customData = null;
      List listQuery = null;
      String CustAccount = "", RecvAccount = "";
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();
      
      try
      {
         CustAccount = jsonData.getString("user");
         RecvAccount = jsonData.getString("receiver");
         
         mapQuery.clear();
         if(RecvAccount != null && RecvAccount.length() > 0)
            mapQuery.put("custName", RecvAccount);
         else
            mapQuery.put("custAccount", CustAccount);
         //mapQuery.put("custAccount", RecvAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            //接收者不存在
            throw new QfdException(3000);
         
         customData = (Custom) listQuery.get(0);
         ReceiverID = customData.getCustId();
         
         mapQuery.clear();
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            //客户不存在
            throw new QfdException(2000);
            
         customData = (Custom) listQuery.get(0);
         custqfdData = new Custqfd();
         custqfdData.setReceiverId(ReceiverID);
         custqfdData.setCustId(customData.getCustId());
         custqfdData.setQfdId(jsonData.getInt("qfdid"));
         custqfdData.setQfdText(jsonData.getString("qfdtext"));
         custqfdData.setQfdCoordinateX(jsonData.getString("coordinateX"));
         custqfdData.setQfdCoordinateY(jsonData.getString("coordinateY"));
         custqfdData.setOvertFlag(jsonData.getInt("overtflag"));
         
         save(custqfdData);
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception ePray)
      {
         nStatus = 10000;
         ePray.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "放灯成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else if(nStatus == 2003)
            mapResult.put("message", "密码错误！");
         else
            mapResult.put("message", "放灯失败！");
      }
      
      return mapResult;
   }
   
   public Map customUseLight(JSONObject jsonData)
   {
      int nStatus = 0;
      Integer ReceiverID;
      List listQuery = null;
      Stardeal starData = null;
      Custqfd custqfdData = null;
      boolean bFilterStatus = false;
      List<Stardeal> listStardeal = null;
      Custom customData = null, receiverData = null;
      String CustAccount = "", RecvAccount = "", strContent = "";
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();
      
      try
      {
         CustAccount = jsonData.getString("user");
         RecvAccount = jsonData.getString("receiver");
         
         mapQuery.clear();
         //mapQuery.put("custAccount", RecvAccount);
         if(RecvAccount != null && RecvAccount.length() > 0)
            mapQuery.put("custName", RecvAccount);
         else
            mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(3000);
         
         receiverData = (Custom) listQuery.get(0);
         ReceiverID = receiverData.getCustId();
         
         mapQuery.clear();
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         if(listQuery.size() > 1)
            throw new QfdException(2008);
         
         //判断是否包含关键词
         strContent = jsonData.getString("qfdtext");
         if(keywordManager.containKeyword(strContent) == true)
            bFilterStatus = true;
         
         customData = (Custom) listQuery.get(0);
         custqfdData = new Custqfd();
         custqfdData.setReceiverId(ReceiverID);
         custqfdData.setCustId(customData.getCustId());
         custqfdData.setQfdId(jsonData.getInt("qfdid"));
         custqfdData.setQfdText(jsonData.getString("qfdtext"));
         custqfdData.setQfdCoordinateX(jsonData.getString("coordinateX"));
         custqfdData.setQfdCoordinateY(jsonData.getString("coordinateY"));
         //包含关键词，公开状态设置为LIGHT_FILTER_STATUS(9)
         if(bFilterStatus)
            custqfdData.setOvertFlag(LIGHT_FILTER_STATUS);
         else
            custqfdData.setOvertFlag(jsonData.getInt("overtflag"));
         save(custqfdData);
         
         //放灯给自己，更新实现愿望数量，否则更新帮助他人实现愿望数量
         if(receiverData.getCustId() == customData.getCustId())
         {
            customData.setWishCount(customData.getWishCount()+1);
         }
         else
         {
            customData.setOtherwishCount(customData.getOtherwishCount()+1);
         }
         customManager.update(customData);
         
         //每天首次放灯赠送star
         mapQuery.clear();
         mapQuery.put("custId", customData.getCustId());
         mapQuery.put("orderType", Stardeal.DEAL_TYPE_USELIGHT);
         mapQuery.put("todayHappen", 1);
         listStardeal = stardealManager.findList(mapQuery);
         
         if(listStardeal != null && listStardeal.size() == 0)
         {
            starData = new Stardeal();
            starData.setCustId(customData.getCustId());
            starData.setReceiverId(customData.getCustId());
            starData.setOrderType(Stardeal.DEAL_TYPE_USELIGHT);
            starData.setOrderMoney(0);
            starData.setOrderCount(Stardeal.CUSTOM_USELIGHT_PRESENT_STAR);
            starData.setOrderStatus(1);
            stardealManager.save(starData);
            
            //客户star总数
            customData.setTotalStar(customData.getTotalStar() + Stardeal.CUSTOM_USELIGHT_PRESENT_STAR);
            customManager.update(customData);
            
            mapResult.put("presentstar", Stardeal.CUSTOM_USELIGHT_PRESENT_STAR);
         }
         else
         {
            mapResult.put("presentstar", "0");
         }
         
         //判断是否包含关键词
         if(bFilterStatus)
            throw new QfdException(5005);
         
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception ePray)
      {
         nStatus = 10000;
         ePray.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "放灯成功！");
         else if(nStatus == 5005)
            mapResult.put("message", "祝福语包含敏感词，请检查！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else if(nStatus == 2003)
            mapResult.put("message", "密码错误！");
         else if(nStatus == 3000)
            mapResult.put("message", "接收用户不存在！");
         else
            mapResult.put("message", "放灯失败！");
      }
      
      return mapResult;
   }
   
   public Map customIncreaseOil(JSONObject jsonData)
   {
      int nStatus = 0;
      Integer CustqfdID;
      String CustAccount = "";
      Timestamp stopTime = null;
      Staruse staruseData = null;
      Custqfd custqfdData = null;
      Custom customData = null;
      List listQuery = null;
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();
      
      try
      {
         CustAccount = jsonData.getString("user");
         CustqfdID = jsonData.getInt("custqfdid");
         
         mapQuery.clear();
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         
         customData = (Custom) listQuery.get(0);
         if(customData.getTotalStar() < LIGHT_OIL_STAR)
            throw new QfdException(8001);
         
         mapQuery.clear();
         mapQuery.put("custqfdId", CustqfdID);
         listQuery = custqfdDao.findList(mapQuery);
         if(listQuery.size() == 0 || CustqfdID == null)
            throw new QfdException(5000);
         
         custqfdData = (Custqfd) listQuery.get(0);
         stopTime = custqfdData.getStopTime();
         stopTime.setTime(stopTime.getTime() + LIGHT_OIL_TIME*24*60*60*1000);

         //延长时间
         custqfdData.setStopTime(stopTime);
         update(custqfdData);
         
         //记录star使用
         staruseData = new Staruse();
         staruseData.setCustId(customData.getCustId());
         staruseData.setReceiverId(customData.getCustId());
         staruseData.setUseType(staruseData.USE_TYPE_OIL);
         staruseData.setUseCount(LIGHT_OIL_STAR);
         staruseManager.save(staruseData);
         
         //扣除luckstar
         customData.setTotalStar(customData.getTotalStar() - LIGHT_OIL_STAR);
         customManager.update(customData);
         
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception ePray)
      {
         nStatus = 10000;
         ePray.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "添加灯油成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else if(nStatus == 5000)
            mapResult.put("message", "祈福灯不存在！");
         else if(nStatus == 2003)
            mapResult.put("message", "密码错误！");
         else if(nStatus == 8001)
            mapResult.put("message", "幸运星数量不足！");
         else
            mapResult.put("message", "添加灯油失败！");
      }
      
      return mapResult;
   }
   
   public Map getCustomLightData(JSONObject jsonData)
   {
      int nStatus = 0, i = 0;
      String CustAccount = "";
      Custom customData = null;
      JSONArray arrayData = null;
      JSONObject jsonCustqfd = null;
      Custqfd custqfdData = null;
      List<Custom> listQuery = null;
      List<Custqfd> listData = null;
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();

      try
      {
         mapQuery.clear();
         CustAccount = jsonData.getString("user");
         mapQuery.put("custAccount", CustAccount);
         mapQuery.put("sortColumns", "create_date desc");
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         
         customData = listQuery.get(0);
         mapQuery.clear();
         mapQuery.put("custId", customData.getId());
         listData = custqfdDao.findList(mapQuery);
         
         arrayData = new JSONArray();
         for(i=0; i<listData.size(); i++)
         {
            custqfdData = listData.get(i);
            jsonCustqfd = new JSONObject();
            jsonCustqfd.put("custqfdid", custqfdData.getCustqfdId());
            jsonCustqfd.put("custid", custqfdData.getCustId());
            jsonCustqfd.put("receiverid", custqfdData.getReceiverId());
            jsonCustqfd.put("custnick", custqfdData.getCustName());
            jsonCustqfd.put("receivernick", custqfdData.getReceiverName());
            jsonCustqfd.put("custimgurl", custqfdData.getCustImgurl());
            jsonCustqfd.put("qfdid", custqfdData.getQfdId());
            jsonCustqfd.put("imgurl", custqfdData.getQfdImgUrl());
            jsonCustqfd.put("usetime", custqfdData.getUseTime());
            jsonCustqfd.put("lefttime", custqfdData.getLeftTime());
            jsonCustqfd.put("overtflag", custqfdData.getOvertFlag());
            jsonCustqfd.put("qfdtext", custqfdData.getQfdText());
            jsonCustqfd.put("coordinateX", custqfdData.getQfdCoordinateX());
            jsonCustqfd.put("coordinateY", custqfdData.getQfdCoordinateY());
            jsonCustqfd.put("praisecount", custqfdData.getPraiseCount());
            jsonCustqfd.put("createtime", custqfdData.getCreateDateString());
            jsonCustqfd.put("stoptime", custqfdData.getStopTimeString());
            
            arrayData.add(jsonCustqfd);
            jsonCustqfd = null;
         }
         
         mapResult.put("lightlist", arrayData);
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception eLogin)
      {
         nStatus = 10000;
         eLogin.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "操作成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else if(nStatus == 2004)
            mapResult.put("message", "密码错误！");
         else
            mapResult.put("message", "操作失败！");
      }
      
      return mapResult;
   }
   
   public Map getNearLightData(JSONObject jsonData)
   {
      int nStatus = 0, i = 0;
      String CustAccount = "";
      //Custom customData = null;
      JSONArray arrayData = null;
      JSONObject jsonCustqfd = null;
      Custqfd custqfdData = null;
      List<Custom> listQuery = null;
      List<Custqfd> listData = null;
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();

      try
      {
         mapQuery.clear();
         CustAccount = jsonData.getString("user");
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         
         //customData = listQuery.get(0);
         mapQuery.clear();
         mapQuery.put("overtFlag", 1);
         mapQuery.put("coordinateX", jsonData.getString("coordinateX"));
         mapQuery.put("coordinateY", jsonData.getString("coordinateY"));
         listData = custqfdDao.findNearList(mapQuery);
         
         arrayData = new JSONArray();
         for(i=0; i<listData.size(); i++)
         {
            custqfdData = listData.get(i);
            jsonCustqfd = new JSONObject();
            jsonCustqfd.put("custqfdid", custqfdData.getCustqfdId());
            jsonCustqfd.put("custid", custqfdData.getCustId());
            jsonCustqfd.put("receiverid", custqfdData.getReceiverId());
            jsonCustqfd.put("custnick", custqfdData.getCustName());
            jsonCustqfd.put("receivernick", custqfdData.getReceiverName());
            jsonCustqfd.put("custimgurl", custqfdData.getCustImgurl());
            jsonCustqfd.put("qfdid", custqfdData.getQfdId());
            jsonCustqfd.put("imgurl", custqfdData.getQfdImgUrl());
            jsonCustqfd.put("usetime", custqfdData.getUseTime());
            jsonCustqfd.put("lefttime", custqfdData.getLeftTime());
            jsonCustqfd.put("overtflag", custqfdData.getOvertFlag());
            jsonCustqfd.put("qfdtext", custqfdData.getQfdText());
            jsonCustqfd.put("coordinateX", custqfdData.getQfdCoordinateX());
            jsonCustqfd.put("coordinateY", custqfdData.getQfdCoordinateY());
            jsonCustqfd.put("praisecount", custqfdData.getPraiseCount());
            jsonCustqfd.put("createtime", custqfdData.getCreateDateString());
            jsonCustqfd.put("stoptime", custqfdData.getStopTimeString());
            
            arrayData.add(jsonCustqfd);
            jsonCustqfd = null;
         }
         
         mapResult.put("lightlist", arrayData);
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception eLogin)
      {
         nStatus = 10000;
         eLogin.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "获取附近祈福灯数据成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else
            mapResult.put("message", "获取附近祈福灯数据失败！");
      }
      
      return mapResult;
   }
   
   @SuppressWarnings("unchecked")
   public Map getLatestLightData(JSONObject jsonData)
   {
      int nStatus = 0, i = 0;
      String CustAccount = "";
      //Custom customData = null;
      Custqfd custqfdData = null;
      JSONArray arrayData = null;
      JSONObject jsonCustqfd = null;
      List<Custom> listQuery = null;
      List<Custqfd> listData = null;
      int nPageSeq = 0, nPageNum = 0, nStartSeq = 0, nStopSeq = 0;
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();

      try
      {
         nPageSeq = new Integer(jsonData.getString("pageseq"));
         nPageNum = new Integer(jsonData.getString("pagenum"));
         nStartSeq = (nPageSeq-1) * nPageNum;
         nStopSeq = nStartSeq + nPageNum;
         
         mapQuery.clear();
         CustAccount = jsonData.getString("user");
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         
         //customData = listQuery.get(0);
         mapQuery.clear();
         mapQuery.put("overtFlag", 1);
         mapQuery.put("startSeq", nStartSeq);
         mapQuery.put("stopSeq", nStopSeq);
         mapQuery.put("sortColumns", "create_date desc");
         listData = custqfdDao.findLatestList(mapQuery);
         System.out.println("startSeq[" + nStartSeq + "] stopSeq[" + nStopSeq + "]");
         
         arrayData = new JSONArray();
         for(i=0; i<listData.size(); i++)
         {
            custqfdData = listData.get(i);
            jsonCustqfd = new JSONObject();
            jsonCustqfd.put("custqfdid", custqfdData.getCustqfdId());
            jsonCustqfd.put("custid", custqfdData.getCustId());
            jsonCustqfd.put("receiverid", custqfdData.getReceiverId());
            jsonCustqfd.put("custnick", custqfdData.getCustName());
            jsonCustqfd.put("receivernick", custqfdData.getReceiverName());
            jsonCustqfd.put("custimgurl", custqfdData.getCustImgurl());
            jsonCustqfd.put("qfdid", custqfdData.getQfdId());
            jsonCustqfd.put("imgurl", custqfdData.getQfdImgUrl());
            jsonCustqfd.put("usetime", custqfdData.getUseTime());
            jsonCustqfd.put("lefttime", custqfdData.getLeftTime());
            jsonCustqfd.put("overtflag", custqfdData.getOvertFlag());
            jsonCustqfd.put("qfdtext", custqfdData.getQfdText());
            jsonCustqfd.put("coordinateX", custqfdData.getQfdCoordinateX());
            jsonCustqfd.put("coordinateY", custqfdData.getQfdCoordinateY());
            jsonCustqfd.put("praisecount", custqfdData.getPraiseCount());
            jsonCustqfd.put("createtime", custqfdData.getCreateDateString());
            jsonCustqfd.put("stoptime", custqfdData.getStopTimeString());
            
            arrayData.add(jsonCustqfd);
            jsonCustqfd = null;
         }
         
         mapResult.put("lightlist", arrayData);
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception eLogin)
      {
         nStatus = 10000;
         eLogin.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "获取附近祈福灯数据成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else
            mapResult.put("message", "获取附近祈福灯数据失败！");
      }
      
      return mapResult;
   }
   
   public Map cutomPraiseLight(JSONObject jsonData)
   {
      int nStatus = 0;
      Integer CustqfdID;
      String CustAccount = "";
      Timestamp stopTime = null;
      Staruse staruseData = null;
      Custqfd custqfdData = null;
      Custom customData = null;
      List listQuery = null;
      Map<String, Object> mapResult = new HashMap<String, Object>();
      Map<String, Object> mapQuery = new HashMap<String, Object>();
      
      try
      {
         CustAccount = jsonData.getString("user");
         CustqfdID = jsonData.getInt("custqfdid");
         
         mapQuery.clear();
         mapQuery.put("custAccount", CustAccount);
         listQuery = customManager.findList(mapQuery);
         if(listQuery.size() == 0 || CustAccount == null || CustAccount.length() == 0)
            throw new QfdException(2000);
         customData = (Custom) listQuery.get(0);

         mapQuery.clear();
         listQuery.clear();
         mapQuery.put("custqfdId", CustqfdID);
         listQuery = custqfdDao.findList(mapQuery);
         if(listQuery.size() == 0 || CustqfdID == null)
            throw new QfdException(5000);
         
         custqfdData = (Custqfd) listQuery.get(0);
         custqfdData.setPraiseCount(custqfdData.getPraiseCount()+1);
         update(custqfdData);
         nStatus = 1000;
      }
      catch(QfdException eQfd)
      {
         nStatus = eQfd.getErrorCode();
      }
      catch(Exception ePray)
      {
         nStatus = 10000;
         ePray.printStackTrace();
      }
      finally
      {
         mapResult.put("statusCode", nStatus);
         if(nStatus == 1000)
            mapResult.put("message", "操作成功！");
         else if(nStatus == 2000)
            mapResult.put("message", "用户不存在！");
         else if(nStatus == 5000)
            mapResult.put("message", "祈福灯不存在！");
         else if(nStatus == 2003)
            mapResult.put("message", "密码错误！");
         else if(nStatus == 8001)
            mapResult.put("message", "幸运星数量不足！");
         else
            mapResult.put("message", "操作失败！");
      }
      
      return mapResult;
   }
   
}
